<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class UsersController extends BaseController {
	/*
	 *显示会员管理页面基本信息
	 */
    public function index(){
    	$sql="select a.*,b.point,b.identify from y_users a left JOIN y_users_detail b on a.id = b.id order by reg_time desc";
    	$M = M();
    	$users=$M->query($sql);
    	$this->assign("users",$users);
        
        //分页显示处理
        $Mess=M("users");
		$count=$Mess->count(); // 总记录数
		$pages = ceil($count / $this->perpage)+1;
		 $nowpage = I("p");
        if(empty($nowpage)){
            $nowpage = 1;
        }
		$Page=new \Think\Page($count,10);
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$show= $Page->show();
		$list=$Mess->alias('a')->join("left join y_users_detail b on a.id=b.id")->limit($Page->firstRow.','.$Page->listRows)->order('reg_time')->select();
		$this->assign("count", $count);
        $this->assign("list", $list);
        $this->assign("page", $show);
        $this->assign("pages", $pages);
        $this->assign("nowpage", $nowpage);
        session_start();
        $id=I("get.");
        $id=$id["id"];
        $_SESSION["pid"]=$id;
        $id=$_SESSION["pid"];
        $M=M("admin_node");
        $node=$M->where("parent_id='$id'")->select();
        $_SESSION["node"]=$node;
		$this->display();
    }
    /*
	 *修改会员信息
	 */
    public function edit_users(){
    	$data=I("get.");
    	$id=$data["id"];
    	$sql="select a.*,b.point,b.identify from y_users a left JOIN y_users_detail b on a.id = b.id where a.id='$id'";
    	$M = M();
    	$users=$M->query($sql);
    	$this->assign("users",$users);
    	$this->display();
    }
    /*
	 *提交修改会员信息
	 */
    public function edit_users_do(){
    	$data=I("post.");
    	$id=$data["id"];
    	$M=M('users');
    	$M->create();
    	$M->where("id='$id'")->save($data);
    	$M=M('users_detail');
    	$M->create();
    	$M->where("id='$id'")->save($data);
    	redirect(U("Users/index"),0,"页面跳转中···");
    }
    /*
	 *提交修改会员信息
	 */
    public function delete_users(){
    	$data=I("get.");
    	$id=$data["id"];
    	$M=M('users');
    	$M->create();
    	$M->where("id='$id'")->delete();
    	$M=M('users_detail');
    	$M->create();
    	$M->where("id='$id'")->delete();
    	redirect(U("Users/index"),0,"页面跳转中···");
    }
    /*
	 *密码修改
	 */
     public function edit_password(){
        $data=I("get.");
        $id=$data["id"];
        $M = M("users");
        $users=$M->where("id='$id'")->select();
        $this->assign("users",$users);
        $this->display();
    } 
    //密码提交 
     public function edit_password_do(){
        $data=I("post.");
        $id=$data["id"];
        $M = M("users");
        $data= $M->create();
        $data["password"]=md5($data["password"]);
        $M->where("id=$id")->save($data);
        redirect(U("Users/index"),0,"页面跳转中···");
    } 
}
